<template>
  <div id="app">
    <el-breadcrumb separator-class="el-icon-arrow-right" style="font-size: 16px;">
      <el-breadcrumb-item :to="{ path: '/' }">
        <i class="el-icon-s-promotion"></i> 后台管理
      </el-breadcrumb-item>
      <el-breadcrumb-item>领养审核</el-breadcrumb-item>
    </el-breadcrumb>
    <el-divider></el-divider>

    <div style="margin-bottom: 20px;">
      <el-button type="primary" size="medium"
                 @click="adoptAgreeList()">查看已领养的宠物
      </el-button>
      <el-button type="primary" size="medium"
                 @click="adoptDisAgreeList">查看未领养的宠物
      </el-button>
    </div>
    <!--宠物列表开始-->
    <el-table :data="adoptArr" border style="width: 100%">
      <el-table-column label="序号" type="index" width="80px"></el-table-column>
      <el-table-column label="查看" type="expand" width="100px">
        <template slot-scope="props">
          <div style="display: inline-block;width: 45%;vertical-align: top">
            <el-form label-position="left" class="demo-table-expand">
              <el-form-item label="用户名:">
                <span>{{ props.row.username }}</span>
              </el-form-item>
              <el-form-item label="性 别:">
                <span>{{ props.row.userSex }}</span>
              </el-form-item>
              <el-form-item label="年 龄:">
                <span>{{ props.row.age }}</span>
              </el-form-item>
              <el-form-item label="电 话:">
                <span>{{ props.row.telephone }}</span>
              </el-form-item>
              <el-form-item label="邮 箱:">
                <span>{{ props.row.email }}</span>
              </el-form-item>
            </el-form>
          </div>
          <div style="display: inline-block;width: 45%;vertical-align: top">
            <el-form label-position="left" class="demo-table-expand">
              <el-form-item label="宠物名称:">
                <span>{{ props.row.petName }}</span>
              </el-form-item>
              <el-form-item label="宠物类型:">
                <span>{{ props.row.petType }}</span>
              </el-form-item>
              <el-form-item label="宠物性别:">
                <span>{{ props.row.petSex }}</span>
              </el-form-item>
              <el-form-item label="宠物生日:">
                <span>{{ props.row.birthday }}</span>
              </el-form-item>
              <el-form-item label="宠物状态:">
                <span>{{ props.row.petState }}</span>
              </el-form-item>
              <el-form-item label="宠物备注:">
                <span>{{ props.row.remark }}</span>
              </el-form-item>
            </el-form>
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="username" label="用户名称" @click="getUserInfo()" width="120px"></el-table-column>
      <el-table-column prop="petName" label="宠物名称" @click="getPetInfo()" width="120px"></el-table-column>
      <el-table-column prop="applyTime" label="申请时间"></el-table-column>
      <el-table-column prop="cause" label="领养原因"></el-table-column>
      <el-table-column prop="sort" label="排序" width="100px"></el-table-column>
      <el-table-column label="查看图片" width="140" align="center">
        <template slot-scope="scope" width="160px">
          <el-button @click="gotoPetPic(scope.row)">查看</el-button>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="240px">
        <template slot-scope="scope">
          <el-button type="primary" size="medium"
                     @click="adoptAgree(scope.row)">
            <i class="el-icon-check"></i>同意
          </el-button>
          <el-button type="danger" size="medium"
                     @click="adoptDisAgree(scope.row)">
            <i class="el-icon-close"></i>不同意
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页控件 -->
    <div style="margin: 10px 0; text-align: right;">
      <el-pagination
          @current-change="changePage"
          :hide-on-single-page="true"
          :page-size="pageSize"
          :current-page="currentPage"
          layout="total, prev, pager, next"
          :total="total">
      </el-pagination>
    </div>
    <!--领养审核结束-->
  </div>
</template>

<script>
export default {
  data() {
    return {
      input: '',
      // 分页相关数据
      currentPage: this.$router.currentRoute.query.page ? parseInt(this.$router.currentRoute.query.page) : 1,
      pageSize: 20,
      pageCount: 1,
      total: 0,
      data: '',
      adoptArr: [],
      userInfo: [],
      petInfo: [],
      // page:'',
    }
  },
  methods: {

    //跳转到宠物图片
    gotoPetPic() {

    },
    //同意申请
    adoptAgree(adopt) {
      let pId  = adopt.petId;
      let url = 'http://localhost:13001//adopt/update-agree?petId' + pId;
      console.log('url = ' + url);
      let localJwt = JSON.parse(localStorage.getItem('localJwt'));
      this.axios
          .create({
            'headers': {
              'Authorization': localJwt.token
            }
          })
          .post(url).then((response) => {
            let jsonResult = response.data;
            if (jsonResult.state == 20000) {
              this.loadAdoptPetList();
            }else {
              this.loadAdoptPetList();
            }
      });
    },
    //不同意申请
    adoptDisAgree(adopt) {

    },
    // 切换分页
    changePage(page) {
      this.$router.replace('?page=' + page);
      console.log("page:" + page);
      this.loadAdoptPetList();
    },
    //加载领养申请列表
    loadAdoptPetList() {
      let page = this.$router.currentRoute.query.page;
      if (!page) {
        page = 1;
      }
      let url = 'http://localhost:13001/adopt/list?pageNum=' + page;
      console.log('url = ' + url);
      let localJwt = JSON.parse(localStorage.getItem('localJwt'));
      this.axios
          .create({
            'headers': {
              'Authorization': localJwt.token
            }
          })
          .get(url).then((response) => {
        let jsonResult = response.data;
        if (jsonResult.state == 20000) {
          this.adoptArr = jsonResult.data.list;
          console.log(this.adoptArr);
          this.currentPage = jsonResult.data.currentPage;
          this.pageSize = jsonResult.data.pageSize;
          this.pageCount = jsonResult.data.maxPage;
          this.total = jsonResult.data.total;
        }
      });
    },
  },
  mounted() {
    this.loadAdoptPetList();
  }
}
</script>

<style scoped>

</style>